using System;
using System.Xml;

namespace AleaClasses
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class TLabel: TTrackEdits
	{
		private string fLabelCode;
		private string fDisplayName;
		private string fDescription;

		private void Constructor(string aLabelCode, string aDisplayName, string aDescription)
		{
			fLabelCode = aLabelCode;
			fDisplayName = aDisplayName;
			fDescription = aDescription;
		}

		public TLabel(string aLabelCode, string aDisplayName, string aDescription)
		{
			Constructor(aLabelCode, aDisplayName, aDescription);
		}

		public TLabel(string aDisplayName, string aDescription)
		{
			Constructor(System.Guid.NewGuid().ToString(), aDisplayName, aDescription);
			SetNeedsSave();
		}

		public TLabel(XmlElement aLabelElem)
		{
			string lLabelCode;
			string lDisplayName;
			string lDescription;

			XmlElement lValueElem = null;
			
			lValueElem = aLabelElem.SelectSingleNode("LabelCode") as XmlElement;
			lLabelCode = Convert.ToString(lValueElem.InnerText);

			lValueElem = aLabelElem.SelectSingleNode("DisplayName") as XmlElement;
			lDisplayName = Convert.ToString(lValueElem.InnerText);

			lValueElem = aLabelElem.SelectSingleNode("Description") as XmlElement;
			lDescription = Convert.ToString(lValueElem.InnerText);

			Constructor(lLabelCode, lDisplayName, lDescription);
		}

		public XmlElement SaveToXml(XmlDocument aDoc)
		{
			XmlElement retval = null;
			XmlElement elem = null;

			retval = aDoc.CreateElement("Label");

			elem = aDoc.CreateElement("LabelCode");
			elem.InnerText = this.LabelCode;
			retval.AppendChild(elem);

			elem = aDoc.CreateElement("DisplayName");
			elem.InnerText = this.DisplayName;
			retval.AppendChild(elem);

			elem = aDoc.CreateElement("Description");
			elem.InnerText = this.Description;
			retval.AppendChild(elem);

			return retval;
		}

		public string LabelCode
		{
			get
			{
				return fLabelCode;
			}
		}

		public string DisplayName
		{
			get
			{
				return fDisplayName;
			}
			set
			{
				if (!fDisplayName.Equals(value))
				{
					fDisplayName = value;
					SetNeedsSave();
				}
			}
		}

		public string Description
		{
			get
			{
				return fDescription;
			}
			set
			{
				if (!fDescription.Equals(value))
				{
					fDescription = value;
					SetNeedsSave();
				}
			}
		}
	}
}
